package com.hu.dal.mapper;

import com.hu.dal.pojo.User;
import org.apache.ibatis.annotations.*;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

//@Repository 使用接口开发
@Component
public interface UserDao {
    @Insert("INSERT INTO user(name) VALUES(#{userName})")
    void insert(@Param("userName") String name);

    @Select({"SELECT * FROM user order by id LIMIT #{offset},#{pageSize}"})
    @Results({@Result(property = "id", column = "id"), @Result(property = "name", column = "name"), @Result(property = "password", column = "password"), @Result(property = "role", column = "role")})
    List<User> getAll(@Param("offset") int offset, @Param("pageSize") int pageSize);

    @Select("SELECT * FROM user WHERE id = #{id}")
    @Results({@Result(property = "id", column = "id"), @Result(property = "name", column = "name"), @Result(property = "password", column = "password"), @Result(property = "role", column = "role")})
    User getById(int id);

    //
//    @Insert("INSERT INTO users(userName,passWord,user_sex) VALUES(#{userName}, #{passWord}, #{userSex})")
//    void insert(UserEntity user);
//
    @Update("UPDATE user SET name=#{name} WHERE id =#{id}")
    void update(User user);

    @Delete("DELETE FROM user WHERE id =#{id}")
    void delete(int id);
}
